/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023.
 * Description: header for virtual address domain isolation
 * Author: zhuyan
 * Create: 2023-07-14
 */
#ifndef INTERNAL_RTOS_ISOLATION_VM_H
#define INTERNAL_RTOS_ISOLATION_VM_H
#include <linux/mm.h>

#define RTOS_MAP_ISOLATION_VM  0x200000

extern bool isovm_check_mmap_invalid(unsigned long addr, unsigned long flag);
extern bool isovm_check_shm_invalid(unsigned long addr, unsigned long shmflg);

#ifdef CONFIG_RTOS_ISOLATION_VM
static inline void isovm_mmap_get_area(struct vm_unmapped_area_info *info, unsigned long flags,
				const struct mm_struct *mm)
{
	if (flags & RTOS_MAP_ISOLATION_VM) {
		info->low_limit = mm->mmap_iso_base;
		info->high_limit = ISOVM_TASK_SIZE_ISOVM;
	}
}

static inline void isovm_mmap_get_area_topdown(struct vm_unmapped_area_info *info,
					unsigned long flags, unsigned long addr,
					const struct mm_struct *mm)
{
	if (flags & RTOS_MAP_ISOLATION_VM) {
		info->low_limit = ISOVM_TASK_SIZE_NORMAL;
		info->high_limit = arch_get_mmap_base(addr, mm->mmap_iso_base);
	}
}
#endif

#endif
